package com.homestay.dao.impl;

import com.homestay.beans.Admins;
import com.homestay.dao.AdminsDao;
import com.homestay.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

public class AdminsDaoImpl implements AdminsDao {

    QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource());

    @Override
    public Admins Login(String username, String password) {
        try{
            Admins admin = queryRunner.query("SELECT * FROM tb_admins WHERE username=? AND password=?",
                new BeanHandler<Admins>(Admins.class), username, password);
            return admin;
        } catch (Exception e) {
            throw new RuntimeException("Error during login", e);
        }
        
    }
}
